﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_AccountForm
 * 类型：       控制层
 * 功能说明：   监控
 * 作者：       郭晓庆
 * 创建日期：   2008/02/01
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Search.Dao;
using Shpm.App.Search.Bean;

public partial class App_Input_AccountForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            ListItem item = null;
            for (int i = 1950; i < 2050;i++ )
            {
                item = new ListItem();
                item.Value = i.ToString();
                item.Text = i.ToString();
                this.dropYear.Items.Add(item);
            }
            this.dropYear.SelectedValue = DateTime.Now.AddMonths(-1).Year.ToString();
            for (int i = 1; i < 13; i++)
            {
                item = new ListItem();
                item.Value = i.ToString();
                item.Text = i.ToString();
                this.dropMonth.Items.Add(item);
            }
            this.dropMonth.SelectedValue = DateTime.Now.AddMonths(-1).Month.ToString();

            SalesInfoDao dao = new SalesInfoDao();
            SalesInfoBean salesInfoBean = new SalesInfoBean();
            //楼号邦定
            IList list = dao.FindBuilds();
            if (list != null && list.Count > 0)
            {
                list.Insert(0, salesInfoBean);
            }
            else
            {
                list.Add(salesInfoBean);
            }
            this.dropBuildNo.DataSource = list;
            this.dropBuildNo.DataBind();


            //楼层邦定
            list = new ArrayList();
            list.Add(salesInfoBean);
            this.dropFloor.DataSource = list;
            this.dropFloor.DataBind();

            //房间号邦定
            this.dropRoomNo.DataSource = list;
            this.dropRoomNo.DataBind();
            
        }
    }
    protected void btnSrh_Click(object sender, EventArgs e)
    {
        string floor = Request.Form["ctl00$ContentPlaceHolder1$dropFloor"].ToString();
        string room = Request.Form["ctl00$ContentPlaceHolder1$dropRoomNo"].ToString();


        SalesInfoDao salesInfoDao = new SalesInfoDao();
        SalesInfoBean salesInfoBean = new SalesInfoBean();
        salesInfoBean.BuildingNo = this.dropBuildNo.SelectedValue;
        //floor
        IList list = salesInfoDao.FindBuildFloor(salesInfoBean);
        if (list != null && list.Count > 0)
        {
            list.Insert(0, salesInfoBean);
        }
        else
        {
            list = new ArrayList();
            list.Add(salesInfoBean);
        }

        this.dropFloor.DataSource = list;
        this.dropFloor.DataBind();
        this.dropFloor.SelectedValue = floor;

        //room
        salesInfoBean.Floor = floor;
        list = salesInfoDao.FindBuildRoom(salesInfoBean);
        if (list != null && list.Count > 0)
        {
            list.Insert(0, salesInfoBean);
        }
        else
        {
            list = new ArrayList();
            list.Add(salesInfoBean);
        }

        this.dropRoomNo.DataSource = list;
        this.dropRoomNo.DataBind();
        this.dropRoomNo.SelectedValue = room;





        AccountDao dao = new AccountDao();
        MemberReceivableBean bean = new MemberReceivableBean();
        bean.MainMemberNo = string.IsNullOrEmpty(this.txtMemberNo.Text.Trim()) ? null : this.txtMemberNo.Text.Trim();
        bean.MainPosId = string.IsNullOrEmpty(this.txtPosId.Text.Trim()) ? null : this.txtPosId.Text.Trim();
        bean.MainMemberName = string.IsNullOrEmpty(this.txtName.Text.Trim()) ? null : this.txtName.Text.Trim();
        bean.BuildingNo = string.IsNullOrEmpty(this.dropBuildNo.SelectedValue) ? null : this.dropBuildNo.SelectedValue;
        bean.Floor = string.IsNullOrEmpty(this.dropFloor.SelectedValue) ? null : this.dropFloor.SelectedValue;
        bean.RoomNo = string.IsNullOrEmpty(this.dropRoomNo.SelectedValue) ? null : this.dropRoomNo.SelectedValue;
        bean.Year = Convert.ToInt32(this.dropYear.SelectedValue);
        bean.Month = Convert.ToInt32(this.dropMonth.SelectedValue);



        if ("0".Equals(this.radPayFlg.SelectedValue))
        {
            bean.CommitFlg = false;
        }
        else if ("1".Equals(this.radPayFlg.SelectedValue))
        {
            bean.CommitFlg = true;
        }

        ViewState["MEMBER_NO"] = bean.MainMemberNo;
        ViewState["POS_ID"] = bean.MainPosId;
        ViewState["NAME"] = bean.MainMemberName;
        ViewState["BUILDING_NO"] = bean.BuildingNo;
        ViewState["FLOOR"] = bean.Floor;
        ViewState["ROOM_NO"] = bean.RoomNo;
        ViewState["PAY_FLG"] = this.radPayFlg.SelectedValue;
        ViewState["YEAR"] = this.dropYear.SelectedValue;
        ViewState["MONTH"] = this.dropMonth.SelectedValue;


        // hidDate值设置
        int year = Convert.ToInt32(this.dropYear.SelectedValue);
        int month = Convert.ToInt32(this.dropMonth.SelectedValue);
        DateTime date1 = new DateTime(year, month, 1);
 
   
        this.hidDate.Value = date1.ToShortDateString() + "--" + date1.AddMonths(1).AddDays(-1).ToShortDateString();


        list = dao.FindMemberInfo(bean);
        this.GridView1.PageIndex = 0;
        this.GridView1.DataSource = list;
        this.GridView1.DataBind();
       

        this.btnPrint1.Visible = list.Count > 0;

        //hidReceivableId值设置
        for (int i = 0; i < list.Count;i++ )
        {
            if (i == 0)
            {
                this.hidReceivableIds.Value = (list[i] as MemberReceivableBean).ReceivableId.ToString();
            }
            else 
            {
                this.hidReceivableIds.Value =this.hidReceivableIds.Value+ ","+(list[i] as MemberReceivableBean).ReceivableId.ToString();
            }
        }
        
       
        //帐单明细恢复
        this.labApartmentNo.Text = string.Empty;
        this.labMainMemberName.Text = string.Empty;
        this.labMainMemberNo.Text = string.Empty;
        this.labSecondMemberNo.Text = string.Empty;
        this.labSecondMemberName.Text = string.Empty;
        this.labMainPosId.Text = string.Empty;
        this.labSecondPosId.Text = string.Empty;
        this.labStatus.Text = string.Empty;
        this.labCount.Text = string.Empty;
        this.GridView2.DataSource = null;
        this.GridView2.DataBind();
        this.GridView2.PageIndex = 0;
        this.btnPrint.Visible = false;

    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int row = (sender as GridView).SelectedIndex;
        int receivableId = Convert.ToInt32((sender as GridView).DataKeys[row].Values[0]);
        ViewState["COUNT"] = 0.00;
        AccountDao dao = new AccountDao();

        MemberReceivableBean memberReceivableBean = new MemberReceivableBean();
        memberReceivableBean.ReceivableId = receivableId;
        memberReceivableBean.Year = Convert.ToInt32(ViewState["YEAR"]);
        memberReceivableBean.Month = Convert.ToInt32(ViewState["MONTH"]);
        IList list = dao.FindMemberInfo(memberReceivableBean);
        if(list.Count>0)
        {
            memberReceivableBean = list[0] as MemberReceivableBean;
            this.labApartmentNo.Text = memberReceivableBean.ApartmentNo;
            this.labMainMemberName.Text = memberReceivableBean.MainMemberName;
            this.labMainMemberNo.Text = memberReceivableBean.MainMemberNo;
            this.labSecondMemberNo.Text = memberReceivableBean.SecondaryMemberNo;
            this.labSecondMemberName.Text = memberReceivableBean.SecondaryMemberName;
            this.labMainPosId.Text = memberReceivableBean.MainPosId;
            this.labSecondPosId.Text = memberReceivableBean.SecondPosId;
            this.labStatus.Text = memberReceivableBean.CommitFlg.Value ? "已缴费" : "未缴费";

            MemberReceivableDetailBean bean = new MemberReceivableDetailBean();
            bean.ReceivableId = receivableId;
            ViewState["RECEIVABLE_ID"] = receivableId;
            list = dao.FindAccountDetail(bean);
            this.GridView2.DataSource = list;
            this.GridView2.DataBind();
            this.GridView2.PageIndex = 0;

            double count = 0.00;
            for (int i = 0; i < list.Count;i++ )
            {
                bean = (list[i] as MemberReceivableDetailBean);
                count = count + Convert.ToDouble(bean.ReceivableAmount);
            }
            this.labCount.Text = string.Format("{0:N}", count);
        }
        this.btnPrint.Visible = list.Count > 0;
        this.hidReceivableId.Value = receivableId.ToString();
 
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        GridView1.PageIndex = e.NewPageIndex;

        AccountDao dao = new AccountDao();
        MemberReceivableBean bean = new MemberReceivableBean();
        bean.MainMemberNo = string.IsNullOrEmpty(Convert.ToString(ViewState["MEMBER_NO"])) ? null : Convert.ToString(ViewState["MEMBER_NO"]);
        bean.MainPosId = string.IsNullOrEmpty(Convert.ToString(ViewState["POS_ID"])) ? null : Convert.ToString(ViewState["POS_ID"]);
        bean.MainMemberName = string.IsNullOrEmpty(Convert.ToString(ViewState["NAME"])) ? null : Convert.ToString(ViewState["NAME"]);
        bean.BuildingNo = string.IsNullOrEmpty(Convert.ToString(ViewState["BUILDING_NO"])) ? null : Convert.ToString(ViewState["BUILDING_NO"]);
        bean.Floor = string.IsNullOrEmpty(Convert.ToString(ViewState["FLOOR"])) ? null : Convert.ToString(ViewState["FLOOR"]);
        bean.RoomNo = string.IsNullOrEmpty(Convert.ToString(ViewState["ROOM_NO"])) ? null : Convert.ToString(ViewState["ROOM_NO"]);
        bean.Year = Convert.ToInt32(ViewState["YEAR"]);
        bean.Month = Convert.ToInt32(ViewState["MONTH"]);
        string flg = Convert.ToString(ViewState["PAY_FLG"]);
        if ("0".Equals(flg))
        {
            bean.CommitFlg = false;
        }
        else if ("1".Equals(flg))
        {
            bean.CommitFlg = true;
        }

        IList list = dao.FindMemberInfo(bean);
        this.GridView1.DataSource = list;
        this.GridView1.DataBind();

    }

    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        GridView2.PageIndex = e.NewPageIndex;

        AccountDao dao = new AccountDao();
        MemberReceivableDetailBean bean = new MemberReceivableDetailBean();
        bean.ReceivableId = Convert.ToInt32(ViewState["RECEIVABLE_ID"]);
        IList list = dao.FindAccountDetail(bean);
        this.GridView2.DataSource = list;
        this.GridView2.DataBind();

    }
    
}
